/*
 * Copyright (c) 2006-2021, Ulandlink Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-10-25     xpw          first version
 */

#ifndef __AT_DEVICE_W15_H__
#define __AT_DEVICE_W15_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdlib.h>

#include <at_device.h>

/* The maximum number of sockets supported by the w15 device */
#define AT_DEVICE_W15_SOCKETS_NUM       4

#ifndef WIFI_SSID_MAX_LENGTH
#define WIFI_SSID_MAX_LENGTH  (32)   /* SSID MAX LEN */
#endif

#ifndef WIFI_PWD_MAX_LENGTH
#define WIFI_PWD_MAX_LENGTH  (32)   /* password MAX LEN */
#endif

#define W15_DEIVCE_NAME  "w15"

typedef struct w15_wifi_ssid
{
    rt_uint8_t ssid_len;
    char ssid_val[WIFI_SSID_MAX_LENGTH + 1];
}w15_wifi_ssid_t;

typedef struct w15_wifi_key
{
    rt_uint8_t pwd_len;
    char pwd_val[WIFI_PWD_MAX_LENGTH + 1];
}w15_wifi_key_t;

struct at_device_w15
{
    char *device_name;
    char *client_name;

    int power_pin;
    int reset_pin;
    int as;
    w15_wifi_ssid_t ssid;
    w15_wifi_key_t password;
    size_t recv_line_num;
    struct at_device device;

    void *user_data;
};

typedef struct w15_recv_s
{
    int peer_id[AT_DEVICE_W15_SOCKETS_NUM - 1];
    struct rt_mutex lock;
}w15_recv_t;

#ifdef AT_USING_SOCKET

/* w15 device socket initialize */
int w15_socket_init(struct at_device *device);

/* w15 device class socket register */
int w15_socket_class_register(struct at_device_class *class);

/* w15 device register */
int w15_device_class_register(void);
int w15_device_register(void);

void w15_ping_resp_clear(void);
char *w15_ping_resp_get(void);

w15_device_info w15_device_get_info(void);
int w15_server_enable(struct at_device *device, rt_bool_t is_enabled);

#endif /* AT_USING_SOCKET */

#ifdef __cplusplus
}
#endif

#endif /* __AT_DEVICE_W15_H__ */
